#include <iostream>
using namespace std;
int n;
const int N=1e5+10;
int a[N];
int len;
int f[N];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(len==0||a[i]>f[len])f[++len]=a[i];
        else {
            int l=1,r=len;
            while(l<r)
            {
                int mid=(r+l)/2;
                if(f[mid]>=a[i])r=mid;
                else l=mid+1;
            }
            f[l]=a[i];
        }
    }
    cout<<len;
    return 0;
}
